﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq.Expressions;

namespace Code4WP7SDK
{
    public static class BaseModelEx
    {
        public static void NotifyPropertyChanged<T, TProperty>(this T baseModel, Expression<Func<T, TProperty>> expression) where T : BaseModel
        {
            var memberExpression = expression.Body as MemberExpression;

            if (memberExpression != null)
            {
                string propertyName = memberExpression.Member.Name;
                baseModel.NotifyPropertyChanged(propertyName);
            }
            else
            {
                throw new NotImplementedException();
            }
        }

        public static void NotifyPropertyChanging<T, TProperty>(this T baseModel, Expression<Func<T, TProperty>> expression) where T : BaseModel
        {
            var memberExpression = expression.Body as MemberExpression;

            if (memberExpression != null)
            {
                string propertyName = memberExpression.Member.Name;
                baseModel.NotifyPropertyChanging(propertyName);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
    }
}
